package com.zxkj.utils;

import java.util.UUID;

/**
 * Created by Administrator on 2017/7/11.
 */
public class CommonUtils {
    public static String getUUID() {
        return UUID.randomUUID().toString();
    }

    public static String trimAndRegex(String str) {
        return str.trim().replaceAll(" +", " ");
    }

    /**
     * 小写,多个空格变一个
     *
     * @param str
     * @return
     */
    public static String trimAndRegex2(String str) {
            return str.trim().toLowerCase().replaceAll(" +", " ");
    }

    /**
     * 按$分开，如果不包括逗号则添加\\b，把$换成|
     *
     * @param str
     * @return
     */
    public static String trimAndRegex3(String str) {
        String[] arr = str.split("\\$");
        StringBuilder sb = new StringBuilder();
        for (String term_item : arr) {
            String term_item_trim = term_item.trim().toLowerCase().replaceAll(" +", " ");
            if (!term_item_trim.contains(",")) {
                term_item_trim = "\\b" + term_item_trim + "\\b";
            }
            sb.append("(" + term_item_trim + ")|");
        }

        return sb.deleteCharAt(sb.length() - 1).toString();
    }
}
